/**
 * @author Eduardo Leonne Souza de Oliveira
 * @version 1.0
 * Date: 2011-12-29
 * Last change: 2011-12-29 
 * 
 */

package com.leonne.harpacristabrasileira.activities;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;

import com.leonne.harpacristabrasileira.R;
import com.leonne.harpacristabrasileira.dao.ConfigurationsDAO;
import com.leonne.harpacristabrasileira.tools.MyConstants;

public class ConfigurationsActivity extends Activity {
	
	private RadioGroup rgFontSize;
	private RadioButton btnSmall;
	private RadioButton btnMedium;
	private RadioButton btnLarge;
	private RadioButton btnExtraLarge;
	private ConfigurationsDAO dao;
	private int idAnthem;
    private static final int[] fontSizes = {10, 15, 25, 35};

	
    /**
     * (non-Javadoc)
     * @see android.app.Activity#onCreate(android.os.Bundle)
     */
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.configurations);
        
        Bundle extras = this.getIntent().getExtras();
		this.idAnthem = extras.getInt("IDANTHEM");
        this.rgFontSize = (RadioGroup) findViewById(R.id.rgFontSize);
        this.btnSmall = (RadioButton) findViewById(R.id.optionFontSizeSmall);
        this.btnMedium = (RadioButton) findViewById(R.id.optionFontSizeMedium);
        this.btnLarge = (RadioButton) findViewById(R.id.optionFontSizeLarge);
        this.btnExtraLarge = (RadioButton) findViewById(R.id.optionFontSizeExtraLarge);
        dao = new ConfigurationsDAO(getBaseContext());
        int value = Integer.parseInt(dao.fetchByDescription("FONTSIZE"));
        switch (value){
        	case 0:
        		this.btnSmall.setChecked(true);        		
        		break;
        	case 1:
        		this.btnMedium.setChecked(true);
        		break;
        	case 2:
        		this.btnLarge.setChecked(true);
        		break;
        	case 3:
        		this.btnExtraLarge.setChecked(true);
        		break;
        }
        
        this.rgFontSize.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				int idx = group.indexOfChild(group.findViewById(group.getCheckedRadioButtonId()));

				dao.setFontSize(idx);
				Intent intent;
				MyConstants.ISFAVORITE = false;
				MyConstants.SELECTEDFONTSIZE = idx;
				if (idAnthem == -1) {
					intent = new Intent(ConfigurationsActivity.this, FirstPageActivity.class);
					intent.putExtra("FORCESEARCH", false);
				} else {
					intent = new Intent(ConfigurationsActivity.this, TextContentPageActivity.class);
					intent.putExtra("IDANTHEM", idAnthem);
				}
	    		startActivity(intent);
				overridePendingTransition(R.anim.rotate3d_in_left_to_right, R.anim.rotate3d_out_left_to_right);
			}
		});
        
    }
	
}